package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JsonUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*;
import org.springframework.format.annotation.DateTimeFormat;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;

@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class News {
    public static final int STATE_HOT=1;//推荐
    public static final int STATE_COMMON=0;//正常
    public static final int STATE_DISABLED=-1;//禁用


    private Long id;
    //封面
    private String coverUrl;
    //标题
    private String title;
    //创建时间
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date createTime;
    //发布时间
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date releaseTime;
    //是否发布
    private Boolean isRelease;
    //作者
    //private User author;
    //日报类型
    private NewsType type;
    //状态
    private Integer state;
    //日报摘要
    private String abstracts;
    //日报内容
    private NewsContent content;

    public String getJsonString(){
        HashMap<Object, Object> map = new HashMap();
        map.put("id",id);
        map.put("title",title);
        map.put("abstracts",abstracts);
        map.put("isRelease",isRelease);
        map.put("state",state);
        map.put("coverUrl",coverUrl);

        if(releaseTime!= null ){
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            map.put("releaseTime",simpleDateFormat.format(releaseTime));
        }

        if(type != null){
            map.put("typeId",type.getId());
            map.put("typeName",type.getName());
        }

        /*if(author != null){
            map.put("authorId",author.getId());
            map.put("authorNickName",author.getNickName());
        }*/
        /*return JSON.toJSONString(map);*/
        return JsonUtil.toJsonString(map);
    }


}